package com.anycl.design.behavioral.state.instancewithoutstatepattern;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Television implements ITelevision {

    private TVStateEnum state;

    public Television(TVStateEnum state) {
        this.state = state;
    }

    public TVStateEnum getState() {
        return state;
    }

    public void setState(TVStateEnum state) {
        this.state = state;
    }

    @Override
    public void powerOn() {
        switch (this.state) {
            case STANDBY_STATE:
                // 待机状态进行开机，没有其他效果
                break;
            case POWER_OFF_STATE:
                // 开机后默认属于待机状态
                log.info("开机");
                this.setState(TVStateEnum.STANDBY_STATE);
                break;
            case PLAY_STATE:
            default:
                break;
        }
    }

    @Override
    public void powerOff() {
        switch (this.state) {
            case STANDBY_STATE:
            case PLAY_STATE:
                log.info("关机");
                this.setState(TVStateEnum.POWER_OFF_STATE);
                break;
            case POWER_OFF_STATE:
            default:
                break;
        }
    }

    @Override
    public void play() {
        switch(this.state) {
            case STANDBY_STATE:
                log.info("播放");
                this.setState(TVStateEnum.PLAY_STATE);
                break;
            case PLAY_STATE:
            case POWER_OFF_STATE:
            default:
                break;
        }
    }

    @Override
    public void standby() {
        switch(this.state) {
            case PLAY_STATE:
                log.info("待机");
                this.setState(TVStateEnum.STANDBY_STATE);
                break;
            case STANDBY_STATE:
            case POWER_OFF_STATE:
            default:
                break;
        }
    }
}
